//
//  ViewController.m
//  Sqlite_Demo
//
//  Created by goojje goojje on 12-8-24.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSLog(@"%@",documentPaths);
    NSString *databaseFilePath = [[documentPaths objectAtIndex:0]stringByAppendingPathComponent:@"mydb.sql"];
    if (sqlite3_open([databaseFilePath UTF8String], &database)==SQLITE_OK) {
        NSLog(@"open db ok.");
    }
    
    char *errorMsg;
    const char *createSql = "create table if not exists persons(id integer primary key autoincrement,name text)";
    if (sqlite3_exec(database, createSql, NULL, NULL, &errorMsg)==SQLITE_OK) {
        NSLog(@"create ok.");
    }else {
        NSLog(@"%@",errorMsg);
    }
    
    
    

    
    
    
    
    char *str1 = "1234567890";
    char *str2 = "qwerqwerqwer";
    
    NSLog(@"str1 %s",str1);
    NSLog(@"str1 %c",str1[2]);
    for (int i = 0 ; i<13; i++) {
        NSLog(@"str1 %c",str1[i]);
    }
    

    *str1="sdf";
    NSLog(@"str1 %s   str2 %s",str1,str2);
    
    strcpy113(str1, str2);
    //[self strcpy:str1 :str2];
    NSLog(@"%s  %s",str1 ,str2);
}

char * strcpy113(char *strDestination, const char *strSource){

    char *strD=strDestination;
    while ((*strDestination++=*strSource++)!='\0')
        return strD;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    sqlite3_close(database);
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
